package thread_pool;

/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/5/23
 * Time:15:25
 * withInitial初始化方法一行
 **/
public class PoolDemo27 {

    static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) {
        threadLocal.set("java");
        try {
            String result = threadLocal.get();
            System.out.println("结果:" + result);
        }finally {
            threadLocal.remove();//不可省略且有意义
        }

        String result2 = threadLocal.get();
        System.out.println("结果2："+result2);//null

        //初始化没值就执行initial方法，
        //每次remove之后会执行一次
    }
}
